package com.neusoft.ysu.elm02.controller;


import com.neusoft.ysu.elm02.entity.CommonResult;
import com.neusoft.ysu.elm02.entity.Dept;
import com.neusoft.ysu.elm02.entity.Emp;
import com.neusoft.ysu.elm02.service.IEmpService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.io.UnsupportedEncodingException;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author 作者：赵子鉴
 * @since 2023-08-21
 */
@RestController
@RequestMapping("/emp")
@CrossOrigin
public class EmpController {
    @Autowired
    IEmpService empService;

    @GetMapping("/q/all")
    public CommonResult selectAll(){
        return empService.findAll();
    }

    @GetMapping("/q/job/bypre/{job}")
    public CommonResult selectJobByPre(@PathVariable String job){
        return empService.findJobByPre(job);
    }

    @PutMapping("/add")
    public CommonResult add(@RequestBody Emp emp){
//        考虑主键列的生成策略，为AUTO的时候必须设空
        emp.setDeptno(null);
        return empService.insert(emp);
    }

    @GetMapping("/q/login")
    public CommonResult login(String loginname,String password) throws UnsupportedEncodingException {
        return empService.checkLogin(loginname,password);
    }
}
